﻿using IR.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IR.Common.Utilities
{
    public static class Settings
    {
        /// <summary>
        /// Gets the value of a setting from the settings table
        /// </summary>
        /// <param name="settingName">The setting name</param>
        /// <param name="defalutValue">The value to return if it is not found (default null)</param>
        /// <returns></returns>
        public static string GetSetting(string settingName, string defaultValue = null)
        {
            IREntities context = new IREntities();

            // Search for the setting
            setting currentsetting = context.settings.Find(settingName);

            // If found load it
            if (currentsetting == null)
            {
                return defaultValue;
            }
            else
            {
                return currentsetting.value;
            }
        }

        /// <summary>
        /// Gets the description of a setting from the settings table
        /// </summary>
        /// <param name="settingName">The setting name</param>
        /// <param name="defaultValue">The description to return if it is not found (default null)</param>
        /// <returns></returns>
        public static string GetSettingDescription(string settingName, string defaultValue = null)
        {
            IREntities context = new IREntities();

            // Search for the setting
            setting currentsetting = context.settings.Find(settingName);

            // If found load it
            if (currentsetting == null)
            {
                return defaultValue;
            }
            else
            {
                return currentsetting.description;
            }
        }
    }
}
